/*
 * test_uri.cpp
 *
 *  Created on: Dec 26, 2013
 *      Author: killerg
 */


#include <event2/http.h>
#include <event2/keyvalq_struct.h>
#include <sstream>
#include <string>
#include "share/util.h"

using namespace std;

bool test_uri() {

    char buffer[1024];

    {
        stringstream ss;

        ss<<"appId="<<1324;
        ss<<"&session="<<1324;
        ss<<"&uid="<<1324;
        ss<<"&signature="<<1324;

        auto uri = evhttp_uri_new();
        evhttp_uri_set_scheme(uri, "http");
        evhttp_uri_set_host(uri, "mis.migc.xiaomi.com");
        evhttp_uri_set_path(uri, "/api/biz/service/verifySession.do");
        evhttp_uri_set_query(uri, decode(ss.str().c_str()));


        evhttp_uri_join(uri, buffer, 1024);
        evhttp_uri_free(uri);
        printf("%s\n", buffer);
    }

    {
        auto uri = evhttp_uri_parse(buffer);

        printf("path: %s\n", evhttp_uri_get_path(uri));
        printf("query: %s\n", evhttp_uri_get_query(uri));
        string query = decode(evhttp_uri_get_query(uri));
        printf("decode_query: %s\n", query.c_str());

        evkeyvalq kv;
        evhttp_parse_query_str(query.c_str(), &kv);
        printf("appId: %s", evhttp_find_header(&kv, "appId"));
        printf("session: %s", evhttp_find_header(&kv, "session"));
        printf("uid: %s", evhttp_find_header(&kv, "uid"));
        printf("signature: %s", evhttp_find_header(&kv, "signature"));
        evhttp_clear_headers(&kv);

        evhttp_uri_free(uri);

    }


    return true;
}
